<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>moduleinfo.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_module_moduleinfo.js.html">moduleinfo.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2008 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Defines the goog.module.ModuleInfo class.
<a name="line17"></a> *
<a name="line18"></a> */
<a name="line19"></a>
<a name="line20"></a>goog.provide(&#39;goog.module.ModuleInfo&#39;);
<a name="line21"></a>
<a name="line22"></a>goog.require(&#39;goog.Disposable&#39;);
<a name="line23"></a>goog.require(&#39;goog.functions&#39;);
<a name="line24"></a>goog.require(&#39;goog.module.BaseModule&#39;);
<a name="line25"></a>goog.require(&#39;goog.module.ModuleLoadCallback&#39;);
<a name="line26"></a>
<a name="line27"></a>
<a name="line28"></a>
<a name="line29"></a>/**
<a name="line30"></a> * A ModuleInfo object is used by the ModuleManager to hold information about a
<a name="line31"></a> * module of js code that may or may not yet be loaded into the environment.
<a name="line32"></a> *
<a name="line33"></a> * @param {Array.&lt;string&gt;} deps Ids of the modules that must be loaded before
<a name="line34"></a> *     this one. The ids must be in dependency order (i.e. if the ith module
<a name="line35"></a> *     depends on the jth module, then i &gt; j).
<a name="line36"></a> * @param {string} id The module&#39;s ID.
<a name="line37"></a> * @constructor
<a name="line38"></a> * @extends {goog.Disposable}
<a name="line39"></a> * @final
<a name="line40"></a> */
<a name="line41"></a>goog.module.ModuleInfo = function(deps, id) {
<a name="line42"></a>  goog.Disposable.call(this);
<a name="line43"></a>
<a name="line44"></a>  /**
<a name="line45"></a>   * A list of the ids of the modules that must be loaded before this module.
<a name="line46"></a>   * @type {Array.&lt;string&gt;}
<a name="line47"></a>   * @private
<a name="line48"></a>   */
<a name="line49"></a>  this.deps_ = deps;
<a name="line50"></a>
<a name="line51"></a>  /**
<a name="line52"></a>   * The module&#39;s ID.
<a name="line53"></a>   * @type {string}
<a name="line54"></a>   * @private
<a name="line55"></a>   */
<a name="line56"></a>  this.id_ = id;
<a name="line57"></a>
<a name="line58"></a>  /**
<a name="line59"></a>   * Callbacks to execute once this module is loaded.
<a name="line60"></a>   * @type {Array.&lt;goog.module.ModuleLoadCallback&gt;}
<a name="line61"></a>   * @private
<a name="line62"></a>   */
<a name="line63"></a>  this.onloadCallbacks_ = [];
<a name="line64"></a>
<a name="line65"></a>  /**
<a name="line66"></a>   * Callbacks to execute if the module load errors.
<a name="line67"></a>   * @type {Array.&lt;goog.module.ModuleLoadCallback&gt;}
<a name="line68"></a>   * @private
<a name="line69"></a>   */
<a name="line70"></a>  this.onErrorCallbacks_ = [];
<a name="line71"></a>
<a name="line72"></a>  /**
<a name="line73"></a>   * Early callbacks to execute once this module is loaded. Called after
<a name="line74"></a>   * module initialization but before regular onload callbacks.
<a name="line75"></a>   * @type {Array.&lt;goog.module.ModuleLoadCallback&gt;}
<a name="line76"></a>   * @private
<a name="line77"></a>   */
<a name="line78"></a>  this.earlyOnloadCallbacks_ = [];
<a name="line79"></a>};
<a name="line80"></a>goog.inherits(goog.module.ModuleInfo, goog.Disposable);
<a name="line81"></a>
<a name="line82"></a>
<a name="line83"></a>/**
<a name="line84"></a> * The uris that can be used to retrieve this module&#39;s code.
<a name="line85"></a> * @type {Array.&lt;string&gt;?}
<a name="line86"></a> * @private
<a name="line87"></a> */
<a name="line88"></a>goog.module.ModuleInfo.prototype.uris_ = null;
<a name="line89"></a>
<a name="line90"></a>
<a name="line91"></a>/**
<a name="line92"></a> * The constructor to use to instantiate the module object after the module
<a name="line93"></a> * code is loaded. This must be either goog.module.BaseModule or a subclass of
<a name="line94"></a> * it.
<a name="line95"></a> * @type {Function}
<a name="line96"></a> * @private
<a name="line97"></a> */
<a name="line98"></a>goog.module.ModuleInfo.prototype.moduleConstructor_ = goog.module.BaseModule;
<a name="line99"></a>
<a name="line100"></a>
<a name="line101"></a>/**
<a name="line102"></a> * The module object. This will be null until the module is loaded.
<a name="line103"></a> * @type {goog.module.BaseModule?}
<a name="line104"></a> * @private
<a name="line105"></a> */
<a name="line106"></a>goog.module.ModuleInfo.prototype.module_ = null;
<a name="line107"></a>
<a name="line108"></a>
<a name="line109"></a>/**
<a name="line110"></a> * Gets the dependencies of this module.
<a name="line111"></a> * @return {Array.&lt;string&gt;} The ids of the modules that this module depends on.
<a name="line112"></a> */
<a name="line113"></a>goog.module.ModuleInfo.prototype.getDependencies = function() {
<a name="line114"></a>  return this.deps_;
<a name="line115"></a>};
<a name="line116"></a>
<a name="line117"></a>
<a name="line118"></a>/**
<a name="line119"></a> * Gets the ID of this module.
<a name="line120"></a> * @return {string} The ID.
<a name="line121"></a> */
<a name="line122"></a>goog.module.ModuleInfo.prototype.getId = function() {
<a name="line123"></a>  return this.id_;
<a name="line124"></a>};
<a name="line125"></a>
<a name="line126"></a>
<a name="line127"></a>/**
<a name="line128"></a> * Sets the uris of this module.
<a name="line129"></a> * @param {Array.&lt;string&gt;} uris Uris for this module&#39;s code.
<a name="line130"></a> */
<a name="line131"></a>goog.module.ModuleInfo.prototype.setUris = function(uris) {
<a name="line132"></a>  this.uris_ = uris;
<a name="line133"></a>};
<a name="line134"></a>
<a name="line135"></a>
<a name="line136"></a>/**
<a name="line137"></a> * Gets the uris of this module.
<a name="line138"></a> * @return {Array.&lt;string&gt;?} Uris for this module&#39;s code.
<a name="line139"></a> */
<a name="line140"></a>goog.module.ModuleInfo.prototype.getUris = function() {
<a name="line141"></a>  return this.uris_;
<a name="line142"></a>};
<a name="line143"></a>
<a name="line144"></a>
<a name="line145"></a>/**
<a name="line146"></a> * Sets the constructor to use to instantiate the module object after the
<a name="line147"></a> * module code is loaded.
<a name="line148"></a> * @param {Function} constructor The constructor of a goog.module.BaseModule
<a name="line149"></a> *     subclass.
<a name="line150"></a> */
<a name="line151"></a>goog.module.ModuleInfo.prototype.setModuleConstructor = function(
<a name="line152"></a>    constructor) {
<a name="line153"></a>  if (this.moduleConstructor_ === goog.module.BaseModule) {
<a name="line154"></a>    this.moduleConstructor_ = constructor;
<a name="line155"></a>  } else {
<a name="line156"></a>    throw Error(&#39;Cannot set module constructor more than once.&#39;);
<a name="line157"></a>  }
<a name="line158"></a>};
<a name="line159"></a>
<a name="line160"></a>
<a name="line161"></a>/**
<a name="line162"></a> * Registers a function that should be called after the module is loaded. These
<a name="line163"></a> * early callbacks are called after {@link Module#initialize} is called but
<a name="line164"></a> * before the other callbacks are called.
<a name="line165"></a> * @param {Function} fn A callback function that takes a single argument which
<a name="line166"></a> *    is the module context.
<a name="line167"></a> * @param {Object=} opt_handler Optional handler under whose scope to execute
<a name="line168"></a> *     the callback.
<a name="line169"></a> * @return {goog.module.ModuleLoadCallback} Reference to the callback
<a name="line170"></a> *     object.
<a name="line171"></a> */
<a name="line172"></a>goog.module.ModuleInfo.prototype.registerEarlyCallback = function(
<a name="line173"></a>    fn, opt_handler) {
<a name="line174"></a>  return this.registerCallback_(this.earlyOnloadCallbacks_, fn, opt_handler);
<a name="line175"></a>};
<a name="line176"></a>
<a name="line177"></a>
<a name="line178"></a>/**
<a name="line179"></a> * Registers a function that should be called after the module is loaded.
<a name="line180"></a> * @param {Function} fn A callback function that takes a single argument which
<a name="line181"></a> *    is the module context.
<a name="line182"></a> * @param {Object=} opt_handler Optional handler under whose scope to execute
<a name="line183"></a> *     the callback.
<a name="line184"></a> * @return {goog.module.ModuleLoadCallback} Reference to the callback
<a name="line185"></a> *     object.
<a name="line186"></a> */
<a name="line187"></a>goog.module.ModuleInfo.prototype.registerCallback = function(
<a name="line188"></a>    fn, opt_handler) {
<a name="line189"></a>  return this.registerCallback_(this.onloadCallbacks_, fn, opt_handler);
<a name="line190"></a>};
<a name="line191"></a>
<a name="line192"></a>
<a name="line193"></a>/**
<a name="line194"></a> * Registers a function that should be called if the module load fails.
<a name="line195"></a> * @param {Function} fn A callback function that takes a single argument which
<a name="line196"></a> *    is the failure type.
<a name="line197"></a> * @param {Object=} opt_handler Optional handler under whose scope to execute
<a name="line198"></a> *     the callback.
<a name="line199"></a> * @return {goog.module.ModuleLoadCallback} Reference to the callback
<a name="line200"></a> *     object.
<a name="line201"></a> */
<a name="line202"></a>goog.module.ModuleInfo.prototype.registerErrback = function(
<a name="line203"></a>    fn, opt_handler) {
<a name="line204"></a>  return this.registerCallback_(this.onErrorCallbacks_, fn, opt_handler);
<a name="line205"></a>};
<a name="line206"></a>
<a name="line207"></a>
<a name="line208"></a>/**
<a name="line209"></a> * Registers a function that should be called after the module is loaded.
<a name="line210"></a> * @param {Array.&lt;goog.module.ModuleLoadCallback&gt;} callbacks The array to
<a name="line211"></a> *     add the callback to.
<a name="line212"></a> * @param {Function} fn A callback function that takes a single argument which
<a name="line213"></a> *     is the module context.
<a name="line214"></a> * @param {Object=} opt_handler Optional handler under whose scope to execute
<a name="line215"></a> *     the callback.
<a name="line216"></a> * @return {!goog.module.ModuleLoadCallback} Reference to the callback
<a name="line217"></a> *     object.
<a name="line218"></a> * @private
<a name="line219"></a> */
<a name="line220"></a>goog.module.ModuleInfo.prototype.registerCallback_ = function(
<a name="line221"></a>    callbacks, fn, opt_handler) {
<a name="line222"></a>  var callback = new goog.module.ModuleLoadCallback(fn, opt_handler);
<a name="line223"></a>  callbacks.push(callback);
<a name="line224"></a>  return callback;
<a name="line225"></a>};
<a name="line226"></a>
<a name="line227"></a>
<a name="line228"></a>/**
<a name="line229"></a> * Determines whether the module has been loaded.
<a name="line230"></a> * @return {boolean} Whether the module has been loaded.
<a name="line231"></a> */
<a name="line232"></a>goog.module.ModuleInfo.prototype.isLoaded = function() {
<a name="line233"></a>  return !!this.module_;
<a name="line234"></a>};
<a name="line235"></a>
<a name="line236"></a>
<a name="line237"></a>/**
<a name="line238"></a> * Gets the module.
<a name="line239"></a> * @return {goog.module.BaseModule?} The module if it has been loaded.
<a name="line240"></a> *     Otherwise, null.
<a name="line241"></a> */
<a name="line242"></a>goog.module.ModuleInfo.prototype.getModule = function() {
<a name="line243"></a>  return this.module_;
<a name="line244"></a>};
<a name="line245"></a>
<a name="line246"></a>
<a name="line247"></a>/**
<a name="line248"></a> * Sets this module as loaded.
<a name="line249"></a> * @param {function() : Object} contextProvider A function that provides the
<a name="line250"></a> *     module context.
<a name="line251"></a> * @return {boolean} Whether any errors occurred while executing the onload
<a name="line252"></a> *     callbacks.
<a name="line253"></a> */
<a name="line254"></a>goog.module.ModuleInfo.prototype.onLoad = function(contextProvider) {
<a name="line255"></a>  // Instantiate and initialize the module object.
<a name="line256"></a>  var module = new this.moduleConstructor_;
<a name="line257"></a>  module.initialize(contextProvider());
<a name="line258"></a>
<a name="line259"></a>  // Keep an internal reference to the module.
<a name="line260"></a>  this.module_ = module;
<a name="line261"></a>
<a name="line262"></a>  // Fire any early callbacks that were waiting for the module to be loaded.
<a name="line263"></a>  var errors =
<a name="line264"></a>      !!this.callCallbacks_(this.earlyOnloadCallbacks_, contextProvider());
<a name="line265"></a>
<a name="line266"></a>  // Fire any callbacks that were waiting for the module to be loaded.
<a name="line267"></a>  errors = errors ||
<a name="line268"></a>      !!this.callCallbacks_(this.onloadCallbacks_, contextProvider());
<a name="line269"></a>
<a name="line270"></a>  if (!errors) {
<a name="line271"></a>    // Clear the errbacks.
<a name="line272"></a>    this.onErrorCallbacks_.length = 0;
<a name="line273"></a>  }
<a name="line274"></a>
<a name="line275"></a>  return errors;
<a name="line276"></a>};
<a name="line277"></a>
<a name="line278"></a>
<a name="line279"></a>/**
<a name="line280"></a> * Calls the error callbacks for the module.
<a name="line281"></a> * @param {goog.module.ModuleManager.FailureType} cause What caused the error.
<a name="line282"></a> */
<a name="line283"></a>goog.module.ModuleInfo.prototype.onError = function(cause) {
<a name="line284"></a>  var result = this.callCallbacks_(this.onErrorCallbacks_, cause);
<a name="line285"></a>  if (result) {
<a name="line286"></a>    // Throw an exception asynchronously. Do not let the exception leak
<a name="line287"></a>    // up to the caller, or it will blow up the module loading framework.
<a name="line288"></a>    window.setTimeout(
<a name="line289"></a>        goog.functions.error(&#39;Module errback failures: &#39; + result), 0);
<a name="line290"></a>  }
<a name="line291"></a>  this.earlyOnloadCallbacks_.length = 0;
<a name="line292"></a>  this.onloadCallbacks_.length = 0;
<a name="line293"></a>};
<a name="line294"></a>
<a name="line295"></a>
<a name="line296"></a>/**
<a name="line297"></a> * Helper to call the callbacks after module load.
<a name="line298"></a> * @param {Array.&lt;goog.module.ModuleLoadCallback&gt;} callbacks The callbacks
<a name="line299"></a> *     to call and then clear.
<a name="line300"></a> * @param {*} context The module context.
<a name="line301"></a> * @return {Array.&lt;*&gt;} Any errors encountered while calling the callbacks,
<a name="line302"></a> *     or null if there were no errors.
<a name="line303"></a> * @private
<a name="line304"></a> */
<a name="line305"></a>goog.module.ModuleInfo.prototype.callCallbacks_ = function(callbacks, context) {
<a name="line306"></a>  // NOTE(nicksantos):
<a name="line307"></a>  // In practice, there are two error-handling scenarios:
<a name="line308"></a>  // 1) The callback does some mandatory initialization of the module.
<a name="line309"></a>  // 2) The callback is for completion of some optional UI event.
<a name="line310"></a>  // There&#39;s no good way to handle both scenarios.
<a name="line311"></a>  //
<a name="line312"></a>  // Our strategy here is to protect module manager from exceptions, so that
<a name="line313"></a>  // the failure of one module doesn&#39;t affect the loading of other modules.
<a name="line314"></a>  // Then, we try to report the exception as best we can.
<a name="line315"></a>
<a name="line316"></a>  // Call each callback in the order they were registered
<a name="line317"></a>  var errors = [];
<a name="line318"></a>  for (var i = 0; i &lt; callbacks.length; i++) {
<a name="line319"></a>    try {
<a name="line320"></a>      callbacks[i].execute(context);
<a name="line321"></a>    } catch (e) {
<a name="line322"></a>      errors.push(e);
<a name="line323"></a>    }
<a name="line324"></a>  }
<a name="line325"></a>
<a name="line326"></a>  // Clear the list of callbacks.
<a name="line327"></a>  callbacks.length = 0;
<a name="line328"></a>  return errors.length ? errors : null;
<a name="line329"></a>};
<a name="line330"></a>
<a name="line331"></a>
<a name="line332"></a>/** @override */
<a name="line333"></a>goog.module.ModuleInfo.prototype.disposeInternal = function() {
<a name="line334"></a>  goog.module.ModuleInfo.superClass_.disposeInternal.call(this);
<a name="line335"></a>  goog.dispose(this.module_);
<a name="line336"></a>};
</pre>


</body>
</html>
